package com.ds.util;

import java.util.Random;

public class ArrayUtil {
	
	public static <T extends Comparable<? super T>> void swap(T[] array,int t1,int t2) {
		
		T temp = array[t1];
		array[t1] = array[t2];
		array[t2] = temp;
	}
	
	public static Integer[] genIntArray(int size) {
		
		Integer[] a = new Integer[size];
		
		Random r = new Random();
		
		for(int i = 0; i < size ;i++) {
			a[i] = r.nextInt(size * 10);
		}
		return a;
	}
	
	public static <T extends Comparable<? super T>> void printArray(T[] array) {
		printArray(array,10);
	}
	
	public static <T extends Comparable<? super T>> void printArray(T[] array,int lineSize) {
		
		int size = array.length;

		for(int i = 0;i < size;i++) {
			if(i > 0 && i % lineSize == 0) {
				System.out.println();
			}
			System.out.print(array[i] + " ");
		}
		System.out.println();
	}
	
	public static <T extends Comparable<? super T>> boolean isSorted(T[] array) {
		int size = array.length;
		for(int i = 0;i < size - 1;i++) {
			if(array[i].compareTo(array[i+1]) > 0) {
				return false;
			}
		}
		return true;
		
	}
}
